﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DacSanMienTayOBJ;
using System.Text;

public partial class Proccess_LockAndUnclockAdvPosition : System.Web.UI.Page
{
    private void AdvPositionLockAdnUnclock()
    {
        try
        {
            int advID = int.Parse(Request["advID"]);
            string typeLock = Request["typeLock"];
            string advName = Request["advName"];
            int vt = int.Parse(Request["vt"]);
            int visible = int.Parse(Request["visible"]);
            StringBuilder builder = new StringBuilder();
            if (typeLock == "lock")
            {
                bool rs = AdvPositionBusiness.UpdateVisibleAdvPosition(advID, 0, ConnectionType.AdminConnection);
                if (rs)
                {
                    string status = "Inactive";
                    visible = 0;
                    builder.Append("<td><label id=\"lbAdvID" + vt + "\" title=\"" + advID + "\">" + advID + "</label></td>");
                    builder.Append("<td><input type=\"text\" style=\"width:350px\" value=\"" + advName + "\" id=\"txtName" + vt + "\" /> </td>");
                    builder.Append("<td>" + status + "</td>");
                    builder.Append("<td><input type=\"button\" value=\"Cập nhật\" onclick=\"UpdateAdvName('" + advID + "','" + vt + "','" + visible + "')\" /> </td>");
                    builder.Append("<td>");
                   
                        builder.Append("<input type=\"button\" value=\"UnLock\" onclick=\"LockAndUnclockAdvPosition('" + advID + "','" + vt + "','unlock','" + visible + "')\" />");

                    builder.Append("</td>");
                    Response.Write(builder);
                }
                else
                {
                    Response.Write("errorlock");
                }
                Response.End();
            }
            else if (typeLock == "unlock")
            {
                bool rs = AdvPositionBusiness.UpdateVisibleAdvPosition(advID, 1, ConnectionType.AdminConnection);
                if (rs)
                {
                    string status = "Active";
                    visible = 1;
                    builder.Append("<td><label id=\"lbAdvID" + vt + "\" title=\"" + advID + "\">" + advID + "</label></td>");
                    builder.Append("<td><input type=\"text\" style=\"width:350px\" value=\"" + advName + "\" id=\"txtName" + vt + "\" /> </td>");
                    builder.Append("<td>" + status + "</td>");
                    builder.Append("<td><input type=\"button\" value=\"Cập nhật\" onclick=\"UpdateAdvName('" + advID + "','" + vt + "','" + visible + "')\" /> </td>");
                    builder.Append("<td>");
                   
                    builder.Append("<input type=\"button\" value=\"Lock\" onclick=\"LockAndUnclockAdvPosition('" + advID + "','" + vt + "','lock','" + visible + "')\" />");
                  
                    builder.Append("</td>");
                    Response.Write(builder);
                }
                else
                {
                    Response.Write("errorunlock");
                }
                Response.End();
            }
            
        }
        catch
        {

        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        AdvPositionLockAdnUnclock();
    }
}